package com.francis.spring.framework.aop.aspect;



import com.francis.spring.framework.aop.intercept.FrancisMethodInterceptor;
import com.francis.spring.framework.aop.intercept.FrancisMethodInvocation;
import java.lang.reflect.Method;

/**
 * @Author Francis
 * @Date 2020/11/22 22:33
 * @Version 1.0
 * @Description:
 */
public class FrancisMethodBeforeAdviceInterceptor extends FrancisAbstractAspectAdvice implements FrancisAdvice, FrancisMethodInterceptor {

    private FrancisJoinPoint joinPoint;
    public FrancisMethodBeforeAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    private void before(Method method,Object[] args,Object target) throws Throwable{
        //传送了给织入参数
        //method.invoke(target);
        super.invokeAdviceMethod(this.joinPoint,null,null);

    }
    @Override
    public Object invoke(FrancisMethodInvocation invocation) throws Throwable {
        //从被织入的代码中才能拿到，JoinPoint
        this.joinPoint = invocation;
        before(invocation.getMethod(), invocation.getArguments(), invocation.getThis());
        return invocation.proceed();
    }
}
